<template>
    <h3>添加理财信息</h3>
    <table>
        <tr>
            <td>理财名称</td>
            <td><input type="text" v-model="F_Name"></td>
        </tr>
        <tr>
            <td>年收益</td>
            <td><input type="text" v-model="F_APY"></td>
        </tr>
        <tr>
            <td>理财最低金额</td>
            <td><input type="text" v-model="F_MinMoney"></td>
        </tr>
        <tr>
            <td>风险等级</td>
            <td>
                <select v-model="F_Level">
                    <option value="-1">请选择</option>
                    <option value="2">低等级</option>
                    <option value="3">中等级</option>
                    <option value="4">高等级</option>
                </select>
            </td>
        </tr>

        <tr>
            <td>利息</td>
            <td>
                <select v-model="I_Id">
                    <option value="0">请选择</option>
                    <option v-for="item in str" :key="item.I_Id" :value="item.I_Id">年度{{ item.I_Year
                    }}年，利率{{ item.I_Interest }}</option>
                </select>
            </td>
        </tr>
        <tr>
            <td colspan="2"><button @click="AddFinancing">添加理财信息</button></td>
        </tr>
    </table>
</template>
<script setup lang="ts">
import { ref } from "vue"
import { useRouter } from "vue-router"
import axios from "axios"

const F_Name = ref("");
const F_APY = ref("");
const F_MinMoney = ref();
const F_Level = ref();
const I_Id = ref(0);
const str = ref([
    {
        I_Id: 2,
        I_Year: 1,
        I_Interest: 1.6
    },
    {
        I_Id: 3,
        I_Year: 2,
        I_Interest: 2.1
    },
    {
        I_Id: 4,
        I_Year: 3,
        I_Interest: 2.5
    }
]);

const AddFinancing = () => {
    axios.post('http://localhost:60493/api/Financing/AddFinancing', {
        F_Name: F_Name.value,
        F_APY: F_APY.value,
        F_MinMoney: F_MinMoney.value,
        F_Level: F_Level.value,
        I_Id: I_Id.value
    })
        .then(res => {
            if (res.data > 0) {
                alert("添加成功");
                Jump();
            }
            else {
                alert("添加失败")
                return;
            }
            console.log(res.data);
        })
        .catch(error => {
            console.log(error);
        });
}
const router = useRouter();
const Jump = () => {
    router.push('/Show');
}
</script>